<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <script src="js/axios.min.js"></script>
    <script src="js/jquery-1.11.3.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/vue-router.js"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
</script>


<script src="layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'http://47.94.138.204:7790/example/userroot'
            ,title: '用户数据表'
            ,cols: [[
                {field:'id', title:'ID', width:80, unresize: true, sort: true}
                ,{field:'username', title:'用户名', width:120,unresize: true, edit: 'text'}
                ,{field:'root', title:'用户权限', width:100,unresize: true, edit: 'text', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',unresize: true, width:70}
            ]]
            ,page: true
        });
        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'edit'){
                layer.prompt({
                    formType: 2
                    ,value: data.root
                }, function(value, index){
                    obj.update({
                        root: value
                    });
                    console.log(obj.data);
                    //
                    $.ajax({
                        type:"GET",
                        url:"http://47.94.138.204:7790/admin/userroot?uid=" + obj.data.id +"&root=" + value,
                        success:function(data){
                            alert("http://127.0.0.1:7747/admin/userroot?uid=" + obj.data.id +"&root=" + value)
                        },
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

</body>
</html>